package com.he.controller;

import com.he.DesignPatterns.iterator.Student;
import com.he.service.StuService;
import com.he.test.MyPostBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * @description: TODO
 * @Author: HCL
 * @Date: 2024/11/25 8:52
 */
@RestController
@RequestMapping("/student")
public class StudentController {

    @Autowired
    private StuService stuService;

    @PostMapping("/insert")
    public String insertData(){
        List<Student> studentList = new ArrayList<Student>(){{
            add(new Student(3L,"张三",123));
            add(new Student(3L,"张三",123));
            add(new Student(4L,"王五",222));
        }};
        studentList.forEach(stu->{
            try {
                stuService.insertStu(stu);
            } catch (Exception e) {
                System.out.println("该数据有误");
            }
        });

        return "执行成功";
    }

    @Resource
    private MyPostBean myPostBean;

    @GetMapping("/test")
    public void PostConstruct(){
        myPostBean.hello();
    }
}
